Demystifying Computers

How They Really Work

Osher Lifelong Learning Institute
University of Illinois, Urbana-Champaign

Scott Badman, Instructor


Bubble Sort Algorithm

FOR i FROM data.length - 1 TO 1 EACH -1

FOR j FROM 0 TO i - 1 EACH 1

IF data[ j ] > data[ j + 1 ]

temp = data[ j ]

data[ j ] = data[ j + 1 ]

data[ j + 1 ] = temp

END IF

END FOR

END FOR


Selection Sort Algorithm

FOR i FROM 0 TO data.length - 1 EACH 1

min = i

FOR j FROM i + 1 TO data.length EACH 1

IF data[ j ] < data[ min ]

min = j

END IF

END FOR

temp = data[ i ]

data[ i ] = data[ min ]

data[ min ] = temp

END FOR